
 
	
	
*directory to be changed 
 cd "/Users/eliemurard/Dropbox/immigration welfare attitudes-Freeman/dofile_1718/replication JEG/"

	
	
***************************************************************************
** Figure A.1: Population share of immigrants in Europe
***************************************************************************
	
	
	use  "immigstock_by_country.dta" ,clear 
	
	g pct_for_country =  pop_for_value/( pop_for_value+ pop_nat_value)

	keep  pct_for_country  year country name_country
	 reshape wide pct_for_country  , i(name_country country) j(year)

	graph bar  pct_for_country1990 pct_for_country2000 pct_for_country2010,  over(name_country, label(angle(45)) ) ///
	  ylabel(, angle(horizontal))  graphregion(color(white))   bar (1, color(gs12))  bar (2, color(gs9)) bar (3, color(gs3))   legend( lab(1 "1990") lab(2 "2000") lab(3 "2010")  )  legend(subtitle("Population share of immigrants in"))

	  
***************************************************************************
** Figure A.2: Population share and origins of immigrants in Europe
***************************************************************************
	
	  
	use  "immigstock_by_country.dta" ,clear 

	g pct_country_eu15=  valueEU15/( pop_for_value+ pop_nat_value)
	g pct_country_Europeno15=  (valueEurope- valueEU15)/( pop_for_value+ pop_nat_value)
	g pct_country_Africa=  ( valueAfrica )/( pop_for_value+ pop_nat_value)
	g pct_country_America=  (  valueAmericas)/( pop_for_value+ pop_nat_value)
	g pct_country_middle=  ( valueMiddleEas)/( pop_for_value+ pop_nat_value)
	g pct_country_asia=  valueAsia/( pop_for_value+ pop_nat_value)
	
	g t1= pct_country_eu15
	g t2= pct_country_Europeno15 +t1 
	g t3= pct_country_America + t2
	g t4= pct_country_asia + t3
	g t5= pct_country_Africa + t4
	g t6= pct_country_middle + t5
	
	label var t1 "EU15"
	label var t2 "Europe non-EU15"
	label var t3 "America"
	label var t4 "Asia"
	label var t5 "Africa"
	label var t6 "Middle-East"
	
	foreach v of varlist t* {
	replace `v'=`v'*100
	}		
	twoway area  t6 t5 t4 t3 t2 t1   year, by( name_country, yrescale   note("") graphregion(color(white))    plotregion( icolor(white))  ) ///
	xtitle("")  xlabel(1990 2000 2010) ylabel(, angle(horizontal))
	graph export "${tables}/continents.png", width(1000) replace 
	

	
***************************************************************************
** Figure A.3: Histogram of the 2010 share of immigrants at the regional level 
***************************************************************************
	
	use "replication_data_JEG.dta", clear 
	
	keep if ess_sample ==1	
	keep if sample_Z_pca_score  ==1 
	
	replace  pct_2010= 100* pct_2010 
	g group = 0        if pct_2010  > 0 & pct_2010   < = 2
	forvalues i = 2(2)50{
		replace group = `i' if pct_2010  > `i' & pct_2010  < = `i'+2
		
	}
	qui tabstat pct_2010 , by(group) stat(mean min max)
	replace group=30 if   group==32
	replace group=36 if   pct_2010  >= 36
	
	qui su pct_2010  
	replace group =round(pct_2010 )  if pct_2010  ==r(max)

	g f = 1
	
	collapse (sum) f, by(group)
	egen t = total(f)
	replace f = f/t

	global xxx
	forvalues i = 0(2)22{
	global xxx $xxx `i' "`i'"
	}
	
	twoway 	bar f group, bartype(spanning) bstyle(histogram) 	xlabel( $xxx 42 26 "26" 30 "30" 36 "36" 42 "42"  )   ///
				xtitle(Share of immigrants in 2010) ytitle(Percentage of respondents)  /// 
			ylab(,angle(horizontal)) graphregion(color(white)) name(hist_1928, replace) 
			
			
***************************************************************************
** Figure A.4: Evolution over time in the support for redistribution 
***************************************************************************
	
			
	use "replication_data_JEG.dta", clear 
	
	keep if ess_sample ==1			
			
	collapse (mean)   redis_scale   , by(country  year_ess name_country) 
	bys country: egen miny= min(year_ess)
	bys country: egen redis_scale2002 = max( redis_scale*(year_ess==2002))
	
	g growth_rediscale = redis_scale/redis_scale2002  
	
	twoway ( connected growth_rediscale  year_ess  , sort  ), by( name_country,  note("") graphregion(color(white))    plotregion( icolor(white))  ) ///
	  xtitle("") ytitle("Support for redistribution (base 2002=1)")  ylabel( , angle(horizontal))   note("") 

	  
	  
	  
